package com.atstudy.thread;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * @version v1.0
 * @description:
 * @author: admin
 * @date: 2022/12/22 15:59
 * @copyright: 博为峰
 */
public class ThreadDemo06 {
    public static void main(String[] args) {
        //最多同时处理多少个任务:20
        ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(10, 15, 100,
                TimeUnit.SECONDS, new ArrayBlockingQueue<>(5));
        for (int i = 0; i < 30; i++) {
            threadPoolExecutor.execute(new Runnable() {
                @Override
                public void run() {
                    for (int i = 0; i < 10; i++) {
                        System.out.println(Thread.currentThread().getName() + "-" + i);
                    }
                }
            });
        }
        /*threadPoolExecutor.execute(new Runnable() {
            @Override
            public void run() {
                for (int i = 0; i < 10; i++) {
                    System.out.println(Thread.currentThread().getName() + "-" + i);
                }
            }
        });*/
    }
}
